<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: HCZ <huangchengze@etrol.com>
// +----------------------------------------------------------------------

namespace app\admin\controller\api;
use app\common\controller\Api;

class Config extends Api {
	
	/**
	 * 配置信息
	 * @param string $gorup
	 * @return json
	 */
	public function getConfigList($group = NULL){
		$where = [];
		if($group){
			$where['group'] = $group;
		}
		$info = collection(model('Config')->where($where)->select())->toArray();
		return json(['code'=>1,'msg'=>'','count'=>count($info),'data'=>$info]);
	}
	
	/**
	 * 新增配置信息
	 * @param array $data
	 * @return json
	 */
	public function add($data = null){
		if($data == null){
			$data = input('post.');
		}
		$result = model('Config')->save($data);
		if (false != $result) {
			return json(['code'=>1,'msg'=>'添加成功']);
		} else {
			return json(['code'=>0,'msg'=>$model->getError()]);
		}
	}
	
	public function del($id = null){
		if($id){
			if(model('Config')->destroy($id)){
				return json(['code'=>1,'msg'=>'删除成功']);
			}
		}
		return json(['code'=>0,'msg'=>'删除失败']);
	}
	
	/**
	 * 编辑配置信息
	 * @param array $data
	 * @param string $id
	 * @return json
	 */
	public function edit($data = null,$id = null){
		if($id == null){
			return json(['code'=>0,'msg'=>'配置信息不存在']);
		}
		if($data == null){
			$data = input('post.');
		}
		if(model('Config')->change($data) !== false){
			return json(['code'=>1,'msg'=>'修改成功']);
		}
		return json(['code'=>0,'msg'=>'修改失败']);
	}
	
	/**
	 * 导航图
	 * @param string $id
	 * @return json
	 */
	public function getAerialPhoto($id = null){
		if($id){
			$info = model('Aerialphoto')->find($id)->toArray();
		}else{
			$info = collection(model('Aerialphoto')->select())->toArray();
		}
		return json(['code'=>1,'msg'=>'','count'=>count($info),'data'=>$info]);
	}
	
	/**
	 * 新增导航图
	 * @param string $data
	 * @return Json
	 */
	public function addAerialPhoto($data = null){
		if($data == null){
			$data = input('post.');
		}
		$result = model('Aerialphoto')->save($data);
		if (false != $result) {
			 setlog('Aerialphotoadd','Aerialphoto',session('user_auth.id'));
			return json(['code'=>1,'msg'=>'航拍图添加成功']);
		} else {
			return json(['code'=>0,'msg'=>$model->getError()]);
		}
	}
	
	/**
	 * 编辑导航图
	 * @param array $data
	 * @param string $photoId
	 * @return json
	 */
	public function editAerialPhoto($data = null,$photoId = null){
		if ($photoId == null) {
			return json(['code'=>0,'msg'=>'导航图不存在,请检查']);
		}
		$model = model('Aerialphoto');
		if ($model->change($data)) {
			return json(['code'=>1,'msg'=>'导航图修改成功']);
		}else{
			return json(['code'=>0,'msg'=>'导航图修改失败,请检查']);
		}
		
	}
	
	/**
	 * 删除导航图
	 * @param string $id
	 * @return json
	 */
	public function delAerialPhoto($id = null){
		if($id){
			if(model('Aerialphoto')->destroy($id)){
				return json(['code'=>1,'msg'=>'删除成功']);
			}
		}
		return json(['code'=>0,'msg'=>'删除失败']);
	}
}